package com.spring.framework.ioc.annotation;

import com.spring.framework.config.IocConfig;
import com.spring.framework.config.generator.BeanNameConfig;
import com.spring.framework.model.learn.ReflectWarning;
import com.spring.framework.model.annotation.COOmponentName;
import com.spring.framework.model.annotation.ComponentName;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Spring 注解 IOC
 *
 * @author xuweizhi
 * @since 2020/12/04 17:11
 */
@SuppressWarnings("all")
public class SpringCoreIoc extends ReflectWarning {

	@Test
	public void testAnnotationName() {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(IocConfig.class);
		System.out.println("--------------------");
		//普通外部类，默认bean名称生成器将返回小写的非限定类名。
		System.out.println(context.getBean("componentName", ComponentName.class));
		//普通外部类，如果类名有多个字符并且前两个字符都是大写时，将直接返回简单类名。
		System.out.println(context.getBean("COOmponentName", COOmponentName.class));
		//普通内部类，默认bean名称生成器将返回全限定外部类名$内部类名。
		System.out.println(context.getBean("com.spring.framework.model.annotation.ComponentName$ComponentNameTwo", ComponentName.ComponentNameTwo.class));
		//静态内部类，默认bean名称生成器将返回小写的非限定外部类名.内部类名。
		System.out.println(context.getBean("componentName.ComponentNameThree", ComponentName.ComponentNameThree.class));
	}

	@Test
	public void tetsGenerateName() {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(BeanNameConfig.class);

		//全部都要求全限定类名，则可以获取该bean的实例
		System.out.println(context.getBean("com.spring.framework.model.annotation.ComponentName", ComponentName.class));
		System.out.println(context.getBean("com.spring.framework.model.annotation.ComponentName", ComponentName.class));

		System.out.println(context.getBean("com.spring.framework.model.annotation.COOmponentName", COOmponentName.class));
		System.out.println(context.getBean("com.spring.framework.model.annotation.COOmponentName", COOmponentName.class));

		System.out.println(context.getBean("com.spring.framework.model.annotation.ComponentName$ComponentNameTwo", ComponentName.ComponentNameTwo.class));
		System.out.println(context.getBean("com.spring.framework.model.annotation.ComponentName$ComponentNameTwo", ComponentName.ComponentNameTwo.class));

		System.out.println(context.getBean("com.spring.framework.model.annotation.ComponentName$ComponentNameThree", ComponentName.ComponentNameThree.class));
		System.out.println(context.getBean("com.spring.framework.model.annotation.ComponentName$ComponentNameThree", ComponentName.ComponentNameThree.class));
	}

}
